<?php $sortdirclass = $sortdir ? 'sortup' : 'sortdown' ?>

<script type="text/javascript">
<!--

var PREFS_UPDATE_TIMEOUT;

function table_sortCallback(tableId, column, sortDown)
{
    if (typeof PREFS_UPDATE_TIMEOUT != "undefined") {
        window.clearTimeout(PREFS_UPDATE_TIMEOUT);
    }

    PREFS_UPDATE_TIMEOUT = window.setTimeout('doPrefsUpdate("' + column + '", "' + sortDown + '")', 300);
}

function doPrefsUpdate(column, sortDown)
{
    // Abort if there is no httpclient support.
    if (typeof(HTTPClient) != 'function') {
        return;
    }

    baseurl = '<?php echo Horde::url($registry->get('webroot', 'horde') . '/rpc.php?restCall=horde/setPreference', true) ?>';
    try {
        client = new HTTPClient();
        client.init(baseurl + '&pref=sortby&app=groo&value=' + encodeURIComponent(column.substring(1)));
        client.asyncGET();

        client = new HTTPClient();
        client.init(baseurl + '&pref=sortdir&app=groo&value=' + encodeURIComponent(sortDown));
        client.asyncGET();
    } catch (e) {}
}

// -->
</script>

<table width="100%" id="items" cellspacing="0" class="sortable linedRow nowrap">
<thead>
 <tr class="item">
  <th class="leftAlign nosort" width="20"><?php echo Horde::img('edit.png', _("Edit Item"), '', $registry->getImageDir('horde')) ?></th>
  <th class="leftAlign nosort" width="75">&nbsp;</th>

  <th id="s<?php echo GROO_SORT_TITLE ?>" class="leftAlign<?php echo ($sortby == GROO_SORT_TITLE) ? ' ' . $sortdirclass : '' ?>" width="77%">
    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', GROO_SORT_TITLE)), _("Sort by Item Text"), 'sortlink', '', '', _("_Title")) ?>
  </th>
  <th id="s<?php echo GROO_SORT_MOD_DATE ?>" class="leftAlign<?php echo ($sortby == GROO_SORT_MOD_DATE) ? ' ' . $sortdirclass : '' ?>" width="10%">
    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', GROO_SORT_MOD_DATE)), _("Sort by Item Text"), 'sortlink', '', '', _("_Date")) ?>
  </th>
  <th id="s<?php echo GROO_SORT_CATEGORY ?>" class="leftAlign<?php echo ($sortby == GROO_SORT_CATEGORY) ? ' ' . $sortdirclass : '' ?>" width="10%">
    <?php
    echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', GROO_SORT_CATEGORY)), _("Sort by Category"), 'sortlink', '', '', _("_Category"));
    if (Auth::getAuth() && (!$GLOBALS['prefs']->isLocked('categories') ||
                            !$GLOBALS['prefs']->isLocked('category_colors'))) {
        $categoryUrl = Util::addParameter(Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/prefs.php'), array('app' => 'horde', 'group' => 'categories'));
        echo ' ' . Horde::link($categoryUrl, _("Edit categories and colors"), '', '_blank') . Horde::img('colorpicker.png', _("Edit categories and colors"), '', $GLOBALS['registry']->getImageDir('horde')) . '</a>';
    }
    ?>
  </th>
 </tr>
</thead>
<tbody>
